﻿using System;
using SS.Common.DBBuilder;
using SS.Net.AppGen.Generatings;
using SS.Net.AppGen.Models;

namespace SS.Net.AppGen
{
    class Program
    {
        static void Generate()
        {
            IDataContext ctx = null;
            var databaseType = WebConfiguration.Instance.DataBaseType;
            if("SqlServer".Equals(databaseType))
            {
                ctx = new SQLServerDataContext(WebConfiguration.Instance.DataSource, WebConfiguration.Instance.DataBaseName, WebConfiguration.Instance.UserName, WebConfiguration.Instance.Password);
            }
            else if("SqlServerCE".Equals(databaseType))
            {
                ctx = new SQLServerCEDataContext(WebConfiguration.Instance.DataSource);
            }
            else
            {
                Console.WriteLine("DatabaseType {0} is not supported", databaseType);
            }
            
            if(ctx != null)
            {
                var db = ctx.InitDBStructure();
                if (db != null)
                {
                    var gen = new WebGenerating(ctx.InitDBStructure());
                    gen.RequestToGenerate();
                }
                else
                {
                    Console.WriteLine("Cannot init DB structure");
                }
            }
            
            Console.ReadKey(true);
        }

        static void Main(string[] args)
        {
            new BootStrapper().InitIoC();
            Generate();
        }
    }
}
